package com.nc.mem.serial;

import java.nio.ByteBuffer;

/**
 * A serializer defines a contract for writing objects directly into byte buffers.
 * 
 * @author cmuramoto
 */
public interface Serializer {

	/**
	 * Reads the object from a ByteBuffer. This method should be called upon the root object only!
	 * 
	 * @param src
	 * @return
	 */
	Object read(ByteBuffer src);

	/**
	 * Deserializes an object provided it still does not exist
	 * 
	 * @param src
	 * @param s
	 *            - id of the object
	 * @return
	 */
	Object read(ByteBuffer src, int s);

	/**
	 * Writes an object directly into the buffer
	 * 
	 * @param dest
	 * @param root
	 */
	void write(ByteBuffer dest, Object root);

}
